package cn.edu.stu.syllabus.utils;


import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 封装基本的Scheduler转换
 */
public final class RxSchedulerUtils {

    /**
     * 在io线程订阅,在main线程消费
     */
    public static <T> Observable.Transformer<T, T> io2mainSchedulersTransformer() {

        return new Observable.Transformer<T, T>() {
            @Override
            public Observable<T> call(Observable<T> tObservable) {
                return tObservable.subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread());
            }
        };
    }

    /**
     * 在computation线程订阅,在main线程消费
     */
    public static <T> Observable.Transformer<T, T> computation2mainSchedulersTransformer() {

        return new Observable.Transformer<T, T>() {
            @Override
            public Observable<T> call(Observable<T> tObservable) {
                return tObservable.subscribeOn(Schedulers.computation())
                        .observeOn(AndroidSchedulers.mainThread());
            }
        };
    }


}
